package cn.ww.teach.knowledge.design.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Wangwang on 2017/12/12.
 */
public class LoginHandler {
    private List<Subscribe> subscribeList = new ArrayList<>();
    private static LoginHandler mysub = new LoginHandler();

    //订阅
    public void toSub(Subscribe subscribe) {
        subscribeList.add(subscribe);
    }

    public static LoginHandler getSubInterface() {
        return mysub;
    }

    public void notify(User user) {
        mysub.onloginSuccess(user);
    }

    private void onloginSuccess(User user) {
        if (subscribeList != null && subscribeList.size() > 0) {
            for (Subscribe sub : subscribeList) {
                sub.goLoginEvent(user);
            }
        }
    }

}
